/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.unittests.service.services.views;

import opiam.admin.faare.PropertiesManager;
import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.service.services.views.TreeNode;
import opiam.admin.faare.service.services.views.ViewGenerator;
import opiam.admin.faare.unittests.TestResult;
import opiam.admin.faare.unittests.TestUtils;
import opiam.admin.faare.unittests.javabeans.SiteTest;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.apache.log4j.Logger;

import java.io.ByteArrayOutputStream;

import java.util.Hashtable;
import java.util.List;

import javax.swing.tree.DefaultMutableTreeNode;


/**
 * Test of the ViewGenerator service.
 */
public class ViewGeneratorTest extends TestCase
{
    /** Test user DN. */
    private static final String DN_USER = "uid=jreuter, ou=People, dc=mycompany,dc=com";

    /** Test user login. */
    private static final String LOGIN_USER = "jreuter"; //uid

    /** Test user password. */
    private static final String PASSWORD_USER = "destroy";

    /** User context. */
    private static UserContext _USERCONTEXT = new UserContext();

    /** Instance of logger. */
    private static Logger _logger = Logger.getLogger(ViewGeneratorTest.class);

    /** Instance of the trace class. */
    private static TestUtils _test = new TestUtils(_logger);

    /** Identifier of the treeview. */
    private static final String TREEVIEW_ID_NAME = "treeview_id";

    /** Name of the treeview hashtable representation. */
    private static final String TREEVIEW_HASHTABLE_NAME = "treeview_hashtable";

    /** Name of the orgchart hashtable representation. */
    private static final String ORGCHART_HASHTABLE_NAME = "orgchart_hashtable";

    /** Identifier of the orgchart. */
    private static final String ORGCHART_ID_NAME = "orgchart_id";

    /** Number of views defined in the views.xml file. */
    private static final int VIEWS_NUMBER = 5;

    /** DN of the site type entry. */
    private static final String DN_SITE = "l=Santa Clara,ou=Sites,dc=mycompany,dc=com";

    /** Name of a view defined in the views.xml file. */
    private static final String VIEW_NAME = "Vue Logique";

    /** Horizontal direction. */
    private static final String HORIZONTAL_DIRECTION = "1";

    /** Vertical direction. */
    private static final String VERTICAL_DIRECTION = "2";

    /** File tree direction. */
    private static final String FILETREE_DIRECTION = "3";

    /** Mode fo orgchart. */
    private static final String ORGCHART_MODE = "1";

    /** JPG image type. */
    private static final String JPG_IMAGE_TYPE = "jpg";

    /** GIF image type. */
    private static final String GIF_IMAGE_TYPE = "gif";

    /** PNG image type. */
    private static final String PNG_IMAGE_TYPE = "png";

    /** Vertical image prefix. */
    private static final String PREF_IMAGE_V = "Vertical_";

    /** Horizontal image prefix. */
    private static final String PREF_IMAGE_H = "Horizontal_";

    /** Image file name. */
    private static final String IMAGE_NAME = "orgchart.";

    /** Image file path. */
    private static final String IMAGE_PATH = "opiam.admin/faare/unittests/data/";

    /** PDF file name. */
    private static final String PDF_NAME = "orgchart.pdf";

    /** PDF file path. */
    private static final String PDF_PATH = "opiam.admin/faare/unittests/data/";

    /**
     * Creates a new ViewGenerator object.
     *
     * @param param  Parameter.
     */
    public ViewGeneratorTest(String param)
    {
        super(param);

        try
        {
            PropertiesManager.getInstance();

            if (!_USERCONTEXT.isLoggedIn())
            {
                StandardService.logon(LOGIN_USER, PASSWORD_USER, _USERCONTEXT);
            }
        }
        catch (Exception e)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("ViewGeneratorTest constructor error");
            msg.append(TestUtils.NEXT);
            msg.append(e.toString());
            _test.displayResultError(msg.toString());
        }
    }

    /**
     * Method of the tests suite.
     *
     * @return Tests result.
     */
    public static Test suite()
    {
        TestSuite suite = new TestSuite();

        suite.addTest(new ViewGeneratorTest("testBegin"));

        // TESTS SET
        suite.addTest(new ViewGeneratorTest("testGetViewNamesList"));
        suite.addTest(new ViewGeneratorTest("testGenerateTreeView"));
        suite.addTest(new ViewGeneratorTest("testGenerateOrgChart"));
        suite.addTest(new ViewGeneratorTest("testGenerateOrgChartAsGif"));
        suite.addTest(new ViewGeneratorTest("testGenerateOrgChartAsJpgOrPng"));
        suite.addTest(new ViewGeneratorTest("testGetTextOrgChart"));
        suite.addTest(new ViewGeneratorTest("testEnd"));

        return (suite);
    }

    /**
     * Main method of the test class.
     *
     * @param args  Sets of the parameters.
     */
    public static void main(String[] args)
    {
        junit.textui.TestRunner.run(suite());
    }

    /**
     * Method to indicate the beginning of the class test.
     *
     */
    public static void testBegin()
    {
        //  To initialize the tests statement
        TestResult.getInstance().setInitiator("ViewGeneratorTest");

        _test.displayHeaderClass("ViewGeneratorTest");
        assertTrue(true);
    }

    /**
     * Method to indicate the end of the class test.
     *
     */
    public static void testEnd()
    {
        _test.displayFooterClass(null);
        assertTrue(true);

        // To display the tests statement
        _test.displayTestStatement("ViewGeneratorTest");
    }

    /**
     * Test the getViewNamesList method.
     *
     */
    public static void testGetViewNamesList()
    {
        _test.displayHeaderMethod("GetViewNamesList");

        try
        {
            List viewsList = ViewGenerator.getViewNamesList();

            if (viewsList != null)
            {
                if (viewsList.size() == VIEWS_NUMBER)
                {
                    _test.displayResultSuccess(null);
                }
                else
                {
                    _test.displayResultFailure("the list size is " +
                        viewsList.size());
                }
            }
            else
            {
                _test.displayResultFailure(
                    "the list of the views names is null");
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("GetViewNamesList");
    }

    /**
     * Test the generateTreeView methods.
     *
     */
    public void testGenerateTreeView()
    {
        _test.displayHeaderMethod("testGenerateTreeView");

        try
        {
            _test.displayMsg(TestUtils.NEXT + "Parameters = List, usercontext");

            try
            {
                List viewsList = ViewGenerator.getViewNamesList();

                if ((viewsList != null) && (viewsList.size() > 0))
                {
                    TreeNode treeNode = ViewGenerator.generateTreeView(viewsList,
                            _USERCONTEXT);

                    if (treeNode != null)
                    {
                        Integer generatedId = (Integer) _USERCONTEXT.getParameters()
                                                                     .get(TREEVIEW_ID_NAME);

                        if (generatedId != null)
                        {
                            Hashtable hnodes = (Hashtable) _USERCONTEXT.getParameters()
                                                                       .get(TREEVIEW_HASHTABLE_NAME);

                            if ((hnodes != null) && (hnodes.size() > 0))
                            {
                                _test.displayResultSuccess(null);
                            }
                            else
                            {
                                _test.displayResultFailure(TREEVIEW_HASHTABLE_NAME +
                                    " is null or empty");
                            }
                        }
                        else
                        {
                            _test.displayResultFailure(TREEVIEW_ID_NAME + " " +
                                generatedId);
                        }
                    }
                    else
                    {
                        _test.displayResultFailure("No treeNode");
                    }
                }
                else
                {
                    _test.displayResultFailure(
                        "List of view names is null or empty");
                }
            }
            catch (Exception e)
            {
                StringBuffer msg = new StringBuffer();
                msg.append("Exception : ");
                msg.append(TestUtils.NEXT);
                msg.append(e.toString());
                _test.displayResultError(msg.toString());
            }

            TreeNode treeNode = null;
            _test.displayMsg(TestUtils.NEXT +
                "Parameters = viewName : Vue Logique, usercontext");

            try
            {
                treeNode = ViewGenerator.generateTreeView("Vue Logique",
                        _USERCONTEXT);

                if (treeNode != null)
                {
                    Integer generatedId = (Integer) _USERCONTEXT.getParameters()
                                                                 .get(TREEVIEW_ID_NAME);

                    if (generatedId != null)
                    {
                        Hashtable hnodes = (Hashtable) _USERCONTEXT.getParameters()
                                                                   .get(TREEVIEW_HASHTABLE_NAME);

                        if ((hnodes != null) && (hnodes.size() > 0))
                        {
                            _test.displayResultSuccess(null);
                        }
                        else
                        {
                            _test.displayResultFailure(TREEVIEW_HASHTABLE_NAME +
                                " is null or empty");
                        }
                    }
                    else
                    {
                        _test.displayResultFailure(TREEVIEW_ID_NAME + " " +
                            generatedId);
                    }
                }
                else
                {
                    _test.displayResultFailure("No treeNode");
                }
            }
            catch (Exception e)
            {
                StringBuffer msg = new StringBuffer();
                msg.append("Exception : ");
                msg.append(TestUtils.NEXT);
                msg.append(e.toString());
                _test.displayResultError(msg.toString());
            }

            _test.displayMsg(TestUtils.NEXT +
                "Parameters = treeNode, nodeid, usercontext");

            try
            {
                treeNode = ViewGenerator.generateTreeView(treeNode,
                        new String("1"), _USERCONTEXT);

                if (treeNode != null)
                {
                    Integer generatedId = (Integer) _USERCONTEXT.getParameters()
                                                                 .get(TREEVIEW_ID_NAME);

                    if (generatedId != null)
                    {
                        Hashtable hnodes = (Hashtable) _USERCONTEXT.getParameters()
                                                                   .get(TREEVIEW_HASHTABLE_NAME);

                        if ((hnodes != null) && (hnodes.size() > 0))
                        {
                            _test.displayResultSuccess(null);
                        }
                        else
                        {
                            _test.displayResultFailure(TREEVIEW_HASHTABLE_NAME +
                                " is null or empty");
                        }
                    }
                    else
                    {
                        _test.displayResultFailure(TREEVIEW_ID_NAME + " " +
                            generatedId);
                    }
                }
                else
                {
                    _test.displayResultFailure("No treeNode");
                }
            }
            catch (Exception e)
            {
                StringBuffer msg = new StringBuffer();
                msg.append("Exception : ");
                msg.append(TestUtils.NEXT);
                msg.append(e.toString());
                _test.displayResultError(msg.toString());
            }

            _test.displayMsg(TestUtils.NEXT + "Parameters = usercontext");

            try
            {
                TreeNode nTreeNode = ViewGenerator.generateTreeView(_USERCONTEXT);

                if (nTreeNode != null)
                {
                    Integer generatedId = (Integer) _USERCONTEXT.getParameters()
                                                                 .get(TREEVIEW_ID_NAME);

                    if (generatedId != null)
                    {
                        Hashtable hnodes = (Hashtable) _USERCONTEXT.getParameters()
                                                                   .get(TREEVIEW_HASHTABLE_NAME);

                        if ((hnodes != null) && (hnodes.size() > 0))
                        {
                            _test.displayResultSuccess(null);
                        }
                        else
                        {
                            _test.displayResultFailure(TREEVIEW_HASHTABLE_NAME +
                                " is null or empty");
                        }
                    }
                    else
                    {
                        _test.displayResultFailure(TREEVIEW_ID_NAME + " " +
                            generatedId);
                    }
                }
                else
                {
                    _test.displayResultFailure("No treeNode");
                }
            }
            catch (Exception e)
            {
                StringBuffer msg = new StringBuffer();
                msg.append("Exception : ");
                msg.append(TestUtils.NEXT);
                msg.append(e.toString());
                _test.displayResultError(msg.toString());
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGenerateTreeView");
    }

    /**
     * Tests the generateOrgChart method.
     *
     */
    public static void testGenerateOrgChart()
    {
        _test.displayHeaderMethod("testGenerateOrgChart");

        try
        {
            SiteTest st = (SiteTest) StandardService.load(DN_SITE, _USERCONTEXT);

            if (st != null)
            {
                _test.displayMsg("Site : " + st.getLieu());
                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction: horizontal, level: 2"); // to indicate the test type

                ByteArrayOutputStream baos = ViewGenerator.generateOrgChart(st,
                        VIEW_NAME, 2, HORIZONTAL_DIRECTION, ORGCHART_MODE,
                        _USERCONTEXT);
                _test.displayMsg("Size of the generated PDF : " + baos.size());

                // allows to create the reference pdf file for the following tests.
                //_test.createFile(PREF_IMAGE_H + PDF_NAME, PDF_PATH, baos.toByteArray());
                // Gets the reference pdf file.
                byte[] refPdf = _test.readBytesFromFile(PREF_IMAGE_H +
                        PDF_NAME, PDF_PATH);
                _test.displayMsg("Size of the reference PDF : " +
                    refPdf.length);

                if (baos.size() == refPdf.length)
                {
                    _test.displayResultSuccess(null);
                }
                else
                {
                    _test.displayResultFailure(null);
                }

                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction: vertical, level: 2"); // to indicate the test type
                baos = ViewGenerator.generateOrgChart(st, VIEW_NAME, 2,
                        VERTICAL_DIRECTION, ORGCHART_MODE, _USERCONTEXT);
                _test.displayMsg("Size of the generated PDF : " + baos.size());

                // allows to create the reference pdf file for the following tests.
                //_test.createFile(PREF_IMAGE_V + PDF_NAME, PDF_PATH,
                //    baos.toByteArray());

                // Gets the reference pdf file.
                refPdf = _test.readBytesFromFile(PREF_IMAGE_V + PDF_NAME,
                        PDF_PATH);
                _test.displayMsg("Size of the reference PDF : " +
                    refPdf.length);

                if (baos.size() == refPdf.length)
                {
                    _test.displayResultSuccess(null);
                }
                else
                {
                    _test.displayResultFailure(null);
                }
            }
            else
            {
                _test.displayResultFailure("No site found for dn : " + DN_SITE);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGenerateOrgChart");
    }

    /**
     * Tests the generateOrgChartAsGif method.
     *
     */
    public static void testGenerateOrgChartAsGif()
    {
        _test.displayHeaderMethod("testGenerateOrgChartAsGif");

        try
        {
            SiteTest st = (SiteTest) StandardService.load(DN_SITE, _USERCONTEXT);

            if (st != null)
            {
                _test.displayMsg("Site : " + st.getLieu());
                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction : horizontal, level=2"); // to indicate the test type

                List orgchart = ViewGenerator.generateOrgChartAsGif(st,
                        VIEW_NAME, 2, HORIZONTAL_DIRECTION, ORGCHART_MODE,
                        _USERCONTEXT);

                if (orgchart != null)
                {
                    ByteArrayOutputStream baos = (ByteArrayOutputStream) orgchart.get(0);

                    // allows to create the reference image file for the following tests.
                    //_test.createFile(PREF_IMAGE_H + IMAGE_NAME + GIF_IMAGE_TYPE, IMAGE_PATH, baos.toByteArray());
                    // Gets the reference image file.
                    byte[] refImage = _test.readBytesFromFile(PREF_IMAGE_H +
                            IMAGE_NAME + GIF_IMAGE_TYPE, IMAGE_PATH);
                    _test.displayMsg("Size of the generated image : " +
                        baos.size());
                    _test.displayMsg("Size of the reference image : " +
                        refImage.length);

                    if (baos.size() == refImage.length)
                    {
                        _test.displayResultSuccess(null);
                    }
                    else
                    {
                        _test.displayResultFailure(null);
                    }
                }
                else
                {
                    _test.displayResultFailure("No orgchart generated");
                }

                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction : horizontal, level=2"); // to indicate the test type
                orgchart = ViewGenerator.generateOrgChartAsGif(st, VIEW_NAME,
                        2, VERTICAL_DIRECTION, ORGCHART_MODE, _USERCONTEXT);

                if (orgchart != null)
                {
                    ByteArrayOutputStream baos = (ByteArrayOutputStream) orgchart.get(0);

                    // allows to create the reference image file for the following tests.
                    //_test.createFile(PREF_IMAGE_V + IMAGE_NAME + GIF_IMAGE_TYPE, IMAGE_PATH, baos.toByteArray());
                    // Gets the reference image file.
                    byte[] refImage = _test.readBytesFromFile(PREF_IMAGE_V +
                            IMAGE_NAME + GIF_IMAGE_TYPE, IMAGE_PATH);
                    _test.displayMsg("Size of the generated image : " +
                        baos.size());
                    _test.displayMsg("Size of the reference image : " +
                        refImage.length);

                    if (baos.size() == refImage.length)
                    {
                        _test.displayResultSuccess(null);
                    }
                    else
                    {
                        _test.displayResultFailure(null);
                    }
                }
                else
                {
                    _test.displayResultFailure("No orgchart generated");
                }
            }
            else
            {
                _test.displayResultFailure("No site found for dn : " + DN_SITE);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGenerateOrgChartAsGif");
    }

    /**
     * Tests the generateOrgChartAsJpgOrPng method.
     *
     */
    public static void testGenerateOrgChartAsJpgOrPng()
    {
        _test.displayHeaderMethod("testGenerateOrgChartAsJpgOrPng");

        try
        {
            SiteTest st = (SiteTest) StandardService.load(DN_SITE, _USERCONTEXT);

            if (st != null)
            {
                _test.displayMsg("Site : " + st.getLieu());
                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction: horizontal, level: 2, image: jpg");

                List orgchart = ViewGenerator.generateOrgChartAsJpgOrPng(st,
                        VIEW_NAME, 2, HORIZONTAL_DIRECTION, ORGCHART_MODE,
                        _USERCONTEXT, JPG_IMAGE_TYPE);

                if (orgchart != null)
                {
                    ByteArrayOutputStream baos = (ByteArrayOutputStream) orgchart.get(0);

                    // allows to create the reference image file for the following tests.
                    //_test.createFile(PREF_IMAGE_H + IMAGE_NAME + JPG_IMAGE_TYPE, IMAGE_PATH, baos.toByteArray());
                    // Gets the reference image file.
                    byte[] refImage = _test.readBytesFromFile(PREF_IMAGE_H +
                            IMAGE_NAME + JPG_IMAGE_TYPE, IMAGE_PATH);
                    _test.displayMsg("Size of the generated image : " +
                        baos.size());
                    _test.displayMsg("Size of the reference image : " +
                        refImage.length);

                    if (baos.size() == refImage.length)
                    {
                        _test.displayResultSuccess(null);
                    }
                    else
                    {
                        _test.displayResultFailure(null);
                    }
                }
                else
                {
                    _test.displayResultFailure("No orgchart generated");
                }

                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction: horizontal, level: 2, image: jpg");
                orgchart = ViewGenerator.generateOrgChartAsJpgOrPng(st,
                        VIEW_NAME, 2, VERTICAL_DIRECTION, ORGCHART_MODE,
                        _USERCONTEXT, JPG_IMAGE_TYPE);

                if (orgchart != null)
                {
                    ByteArrayOutputStream baos = (ByteArrayOutputStream) orgchart.get(0);

                    // allows to create the reference image file for the following tests.
                    //_test.createFile(PREF_IMAGE_V + IMAGE_NAME + JPG_IMAGE_TYPE, IMAGE_PATH, baos.toByteArray());
                    // Gets the reference image file.
                    byte[] refImage = _test.readBytesFromFile(PREF_IMAGE_V +
                            IMAGE_NAME + JPG_IMAGE_TYPE, IMAGE_PATH);
                    _test.displayMsg("Size of the generated image : " +
                        baos.size());
                    _test.displayMsg("Size of the reference image : " +
                        refImage.length);

                    if (baos.size() == refImage.length)
                    {
                        _test.displayResultSuccess(null);
                    }
                    else
                    {
                        _test.displayResultFailure(null);
                    }
                }
                else
                {
                    _test.displayResultFailure("No orgchart generated");
                }

                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction: horizontal, level: 2, image: png"); // to indicate the test type
                orgchart = ViewGenerator.generateOrgChartAsJpgOrPng(st,
                        VIEW_NAME, 2, HORIZONTAL_DIRECTION, ORGCHART_MODE,
                        _USERCONTEXT, PNG_IMAGE_TYPE);

                if (orgchart != null)
                {
                    ByteArrayOutputStream baos = (ByteArrayOutputStream) orgchart.get(0);

                    // allows to create the reference image file for the following tests.
                    //_test.createFile(PREF_IMAGE_H + IMAGE_NAME + PNG_IMAGE_TYPE, IMAGE_PATH, baos.toByteArray());
                    // Gets the reference image file.
                    byte[] refImage = _test.readBytesFromFile(PREF_IMAGE_H +
                            IMAGE_NAME + PNG_IMAGE_TYPE, IMAGE_PATH);
                    _test.displayMsg("Size of the generated image : " +
                        baos.size());
                    _test.displayMsg("Size of the reference image : " +
                        refImage.length);

                    if (baos.size() == refImage.length)
                    {
                        _test.displayResultSuccess(null);
                    }
                    else
                    {
                        _test.displayResultFailure(null);
                    }
                }
                else
                {
                    _test.displayResultFailure("No orgchart generated");
                }

                _test.displayMsg(TestUtils.NEXT +
                    "Parameters = direction: horizontal, level: 2, image: png"); // to indicate the test type
                orgchart = ViewGenerator.generateOrgChartAsJpgOrPng(st,
                        VIEW_NAME, 2, VERTICAL_DIRECTION, ORGCHART_MODE,
                        _USERCONTEXT, PNG_IMAGE_TYPE);

                if (orgchart != null)
                {
                    ByteArrayOutputStream baos = (ByteArrayOutputStream) orgchart.get(0);

                    // allows to create the reference image file for the following tests.
                    //_test.createFile(PREF_IMAGE_V + IMAGE_NAME + PNG_IMAGE_TYPE, IMAGE_PATH, baos.toByteArray());
                    // Gets the reference image file.
                    byte[] refImage = _test.readBytesFromFile(PREF_IMAGE_V +
                            IMAGE_NAME + PNG_IMAGE_TYPE, IMAGE_PATH);
                    _test.displayMsg("Size of the generated image : " +
                        baos.size());
                    _test.displayMsg("Size of the reference image : " +
                        refImage.length);

                    if (baos.size() == refImage.length)
                    {
                        _test.displayResultSuccess(null);
                    }
                    else
                    {
                        _test.displayResultFailure(null);
                    }
                }
                else
                {
                    _test.displayResultFailure("No orgchart generated");
                }
            }
            else
            {
                _test.displayResultFailure("No site found for dn : " + DN_SITE);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGenerateOrgChartAsJpgOrPng");
    }

    /**
     * Tests the getTextOrgChart method.
     *
     */
    public static void testGetTextOrgChart()
    {
        _test.displayHeaderMethod("testGetTextOrgChart");

        try
        {
            SiteTest st = (SiteTest) StandardService.load(DN_SITE, _USERCONTEXT);

            if (st != null)
            {
                _test.displayMsg("Site : " + st.getLieu());
                _test.displayMsg(TestUtils.NEXT + "Parameters = level: 2"); // to indicate the test type

                DefaultMutableTreeNode dmtn = ViewGenerator.getTextOrgChart(_USERCONTEXT,
                        VIEW_NAME, st, 2);

                if (dmtn != null)
                {
                    _test.displayMsg("Level = " + dmtn.getLevel());
                    _test.displayResultSuccess(null);
                }
                else
                {
                    _test.displayResultFailure("No treeNode");
                }
            }
            else
            {
                _test.displayResultFailure("No site found for dn : " + DN_SITE);
            }
        }
        catch (Exception ex)
        {
            StringBuffer msg = new StringBuffer();
            msg.append("Exception : ");
            msg.append(TestUtils.NEXT);
            msg.append(ex.toString());
            _test.displayResultError(msg.toString());
        }

        _test.displayFooterMethod("testGetTextOrgChart");
    }
}
